package contracts.simpleCodingQuizSubmission

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("POST")
        url("/api/simpleCodingSubmissions")
        headers {
            contentType(applicationJsonUtf8())
        }
        body("""
        {
            "assignmentId": 1,
            "quizId": 1,
            "userId": 1,
            "userAnswer": "https://github.com/tws-online-quiz/java-collection-operator.git",
            "status": 2,
            "answerBranch": "master",
            "jobMessage": "正在初始化,正在上传仓库地址,正在检查答案格式",
            "userAnswerZipUrl": "https://s3.cn-north-1.amazonaws.com.cn/quiz-center-files/user-answer/1543385552729-8c03deb9-728e-43b1-b8a8-bc1c42cbfe2b.zip"
        }
        """)
        bodyMatchers {
            jsonPath('$.userAnswerZipUrl', byRegex("[\\s\\S]+"))
            jsonPath('$.jobMessage', byRegex("[\\s\\S]+"))
            jsonPath('$.answerBranch', byRegex("[\\s\\S]+"))
            jsonPath('$.status', byRegex(number()))
            jsonPath('$.userAnswer', byRegex("[\\s\\S]+"))
            jsonPath('$.userId', byRegex(number()))
            jsonPath('$.quizId', byRegex(number()))
            jsonPath('$.assignmentId', byRegex(number()))
        }
    }
    response {
        status(201)
        body("""
        {
            "assignmentId": 1,
            "quizId": 1,
            "userId": 1,
            "userAnswer": "https://github.com/tws-online-quiz/java-collection-operator.git",
            "status": 2,
            "answerBranch": "master",
            "jobMessage": "正在初始化,正在上传仓库地址,正在检查答案格式",
            "userAnswerZipUrl": "https://s3.cn-north-1.amazonaws.com.cn/quiz-center-files/user-answer/1543385552729-8c03deb9-728e-43b1-b8a8-bc1c42cbfe2b.zip"
        }
        """)
        bodyMatchers {
            jsonPath('$.userAnswerZipUrl', byRegex("[\\s\\S]+"))
            jsonPath('$.jobMessage', byRegex("[\\s\\S]+"))
            jsonPath('$.answerBranch', byRegex("[\\s\\S]+"))
            jsonPath('$.status', byRegex(number()))
            jsonPath('$.userAnswer', byRegex("[\\s\\S]+"))
            jsonPath('$.userId', byRegex(number()))
            jsonPath('$.quizId', byRegex(number()))
            jsonPath('$.assignmentId', byRegex(number()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}
